<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>

<c:set var="context" value="${pageContext.request.contextPath}"/>
<c:choose>
    <c:when test="${empty sessionScope.USER_ROLE}">
        <c:redirect url="/welcome.jsp"/>
    </c:when>
    <c:otherwise>
        <c:if test="${sessionScope.USER_ROLE != 'admin'}">
            <c:redirect url="/welcome.jsp"/>
        </c:if>
    </c:otherwise>
</c:choose>
<jsp:useBean id="checkerBean" class="core.XmlChecker"/>
<c:set var="path" value='<%= getServletContext().getRealPath("/")%>'/>
<jsp:setProperty name="checkerBean" property="realPath" value="${path}"/>

<jsp:setProperty name="checkerBean" property="webPath" value="/WEB-INF/XmlDoc/Users.xml"/>
<c:if test="${not checkerBean.validFile}">
    <jsp:forward page="/XmlController">
        <jsp:param name="action" value="UsersXmlCheck"/>
        <jsp:param name="current" value="/management/Admin.jsp"/>
    </jsp:forward>
</c:if>

<jsp:setProperty name="checkerBean" property="webPath" value="/WEB-INF/XmlDoc/UserDetails.xml"/>
<c:if test="${not checkerBean.validFile}">
    <jsp:forward page="/XmlController">
        <jsp:param name="action" value="UserDetailsXmlCheck"/>
        <jsp:param name="current" value="/management/Admin.jsp"/>
    </jsp:forward>
</c:if>

<jsp:setProperty name="checkerBean" property="webPath" value="/WEB-INF/XmlDoc/Products.xml"/>
<c:if test="${not checkerBean.validFile}">
    <jsp:forward page="/XmlController">
        <jsp:param name="action" value="ProductsXmlCheck"/>
        <jsp:param name="current" value="/management/Admin.jsp"/>
    </jsp:forward>
</c:if>

<jsp:setProperty name="checkerBean" property="webPath" value="/WEB-INF/XmlDoc/Comments.xml"/>
<c:if test="${not checkerBean.validFile}">
    <jsp:forward page="/XmlController">
        <jsp:param name="action" value="CommentXmlCheck"/>
        <jsp:param name="current" value="/management/Admin.jsp"/>
    </jsp:forward>
</c:if>

<jsp:setProperty name="checkerBean" property="webPath" value="/WEB-INF/XmlDoc/Orders.xml"/>
<c:if test="${not checkerBean.validFile}">
    <jsp:forward page="/XmlController">
        <jsp:param name="action" value="OrdersXmlCheck"/>
        <jsp:param name="current" value="/management/Admin.jsp"/>
    </jsp:forward>
</c:if>

<jsp:setProperty name="checkerBean" property="webPath" value="/WEB-INF/XmlDoc/OrderDetails.xml"/>
<c:if test="${not checkerBean.validFile}">
    <jsp:forward page="/XmlController">
        <jsp:param name="action" value="OrderDetailsXmlCheck"/>
        <jsp:param name="current" value="/management/Admin.jsp"/>
    </jsp:forward>
</c:if>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Admin Page</title>
        <link href="${context}/res/css/main-style.css" rel="stylesheet" type="text/css" />
        <link href="${context}/res/css/admin-style.css" rel="stylesheet" type="text/css" />
        <link href="${context}/res/css/modal-popup-style.css" rel="stylesheet" type="text/css" />
        <link href="${context}/res/css/checkout.css" rel="stylesheet" type="text/css" />
        <link href="${context}/res/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="${context}/res/css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css" />

        <script language="JavaScript" src="${context}/scripts/UtilsScript.js"></script>
        <script>var contextPath="${pageContext.request.contextPath}"</script>
        <script type="text/javascript" src="${context}/res/js/lightbox.js"></script>
        <script type="text/javascript" src="${context}/scripts/AdminScript.js"></script>

        <script type="text/javascript" src="${context}/scripts/ProductScript.js"></script>
        <script type="text/javascript" src="${context}/scripts/CommentScript.js"></script>
        <script type="text/javascript" src="${context}/scripts/UserScript.js"></script>
        <script type="text/javascript" src="${context}/scripts/OrderScript.js"></script>
        <script type="text/javascript" src="${context}/res/js/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="${context}/res/js/bootstrap.min.js"></script>

    </head>
    <body>
        <div id="PopupContainer" class="white_content">
            <div id="content"></div>
            <img id="btnClose" src="${context}/res/img/buttonclose.png" alt="Close"/>
        </div>
        <div id="fadeOverlay" class="black_overlay">
        </div>
        
        <div id="page-container">
            <div id="header">
                <div class="wrapper">
                    <div class="logo-container">
                        <a href="${pageContext.request.contextPath}"><img src="${pageContext.request.contextPath}/res/img/logo2.png"/></a>
                    </div>

                    <nav class="menu-container">
                        <a href="${pageContext.request.contextPath}">Home</a>
                        <a href="${pageContext.request.contextPath}/about-us.jsp">About us</a>
                        <a href="${pageContext.request.contextPath}/client/product_category.jsp">Products</a>
                    </nav>
                    <div id="personal-container">
                        <ul>
                            <li class="my-account">
                                <h3>Welcome ${sessionScope.USER_NAME}</h3>
                                <h3><a href="../UserController?action=Logout" method="POST">Log out</a></h3>
                            </li>
                        </ul>
                    </div>
                    <div class="spacer" style="clear: both;"></div>
                </div>
            </div>
            <div id="middle-container">
                <div class="wrapper">
                    <div class="tabbable tabs-left">
                        <ul class="nav nav-tabs" id="admin-tab-container">
                            <li class><a flag="user" class="admin-tab current-tab" data-toggle="tab">Users</a></li>
                            <li class><a flag="product" class="admin-tab" data-toggle="tab">Products</a></li>
                            <li class><a flag="order" class="admin-tab" data-toggle="tab">Orders</a></li>
                            <li class><a flag="report" class="admin-tab" data-toggle="tab">Reports</a></li>
                        </ul>
                        <div class="admin-control-container" id="admin-container">

                        </div>
                    </div>
                    <%--      <nav id="admin-tab-container" >
                              <a flag="user" class="admin-tab current-tab">Người Dùng</a>
                              <a flag="product" class="admin-tab">Sản phẩm</a>
                              <a flag="order" class="admin-tab">Đơn Hàng</a>
                              <a flag="report" class="admin-tab">Báo Cáo</a>
                          </nav>

                    <div class="admin-control-container" id="admin-container">
                    </div> <!-- END admin control -->
                    --%>
                </div>
                <div class="spacer" style="clear: both;"></div>
            </div> <!-- end middle-container -->
            <div id="footer">
                <div class="wrapper">
                    <div id="footer-menu">
                        <ul>
                            <li><a href="${pageContext.request.contextPath}">Home</a></li>
                            <li><a href="${pageContext.request.contextPath}/about-us.jsp">About us</a></li>
                            <li><a href="${pageContext.request.contextPath}/contact-us.jsp">Contact</a></li>
                        </ul>
                    </div>
                    <div id="copy-right">
                        <p>
            	Copyright © 2013 Laptops. All rights reserved.<br>
                        </p>
                    </div>
                </div>
            </div> <!-- end footer -->
        </div>
    </body>
</html>
